When you use setjmp() and longjmp() , the only automatic variables guaranteed to remain valid are those declared volatile . This is a consequence of automatic register allocation. If you use the -W option with the -O option, you'll get a warning when GNU CC thinks such a problem is possible. For example:
jmp_buf j;
foo ()
{
int a, b;
a = fun1 ();
if (setjmp (j))
return a;
a = fun2 ();
/* longjmp (j) may occur in fun3. */
return a + fun3 ();
}
Here, a may or may not be restored to its first value when the longjmp() function is called. If a is allocated in a register, its first value is restored; otherwise, it keeps the last value stored in it.